<?php
require_once 'Croese/Google/Chart/Encoding/Text.php';
/**
 * Text encoding with data scaling
 * -------------------------------
 * 
 * Specify text encoding with data scaling with two parameters
 * 
 * chd=t:<chart data string>
 * chds=<data set 1 minimum value>,<data set 1 maximum value>,<data set n minimum value>,<data set n maximum value>
 * 
 * Where:
 * - <chart data string> consists of any positive or negative floating point numbers
 * - <data set 1 minimum value> is the lowest number you want to apply to the first data set
 * - <data set 1 maximum value> is the highest number you want to apply to the first data set, omit to specify 100
 * - <data set n minimum value> is the lowest number you want to apply to the nth data set
 * - <data set n maximum value> is the highest number you want to apply to the nth data set, omit to specify 100
 * 
 * If you supply fewer data scaling parameters than there are data sets the 
 * last scaling parameter is applied to the remaining data sets. Provide just 
 * one pair of scaling parameters to apply a single range to a chart.
 * 
 * Note:
 * - This is not available for maps.
 * - Specify a missing value with a number that is out of range.
 * - If you have more than one set of data, separate each set with a pipe character (|).
 * 
 * For example: chd=t:30,-60,50,120,80&chds=-80,140
 */
class Croese_Google_Chart_Encoding_TextScaling extends Croese_Google_Chart_Encoding_Text 
{

	public $_scaling;
	public $_separator = '&amp;';
	
	/**
	 * Met deze functie encoden we de data op de TextScaling manier.
	 * 
	 * $scaling wordt verwacht als volgt:
	 * array(
	 *     array('min' => value, 'max' => value),
	 *     array('min' => value, 'max' => value),
	 *     ...
	 *     array('min' => value, 'max' => value),
	 * );
	 *
	 * @param array $data
	 * @param array $scaling
	 * @param string $separator
	 */
	public function encode($data)
	{
		if(null == $this->_scaling)
		{
			throw new Exception('$scaling moet wel gezet zijn!');
		}
		
		$encodedData = parent::encode($data);
		
		$scalingData = array();
		foreach ($this->_scaling as $dataSet)
		{
			$scalingData[] = $dataSet['min'];
			$scalingData[] = $dataSet['max'];
		}
		$encodedData .= $this->_separator . 'chds=' . implode(',', $scalingData); // @todo hoe gaan we dit oplossen?
		return $encodedData;
	}
	
	public function setScaling($scaling)
	{
		if(is_array($scaling))
		{
			$this->_scaling = $scaling;
		}
		else
		{
			print("boom");
		}
		/*
		if(is_array($scaling))
		{
			foreach ($scaling as $scale)
			{
				if(is_array($scale))
				{
					
				}
				else
				{
					
				}
			}
		}
		else
		{
			print("grote fout");
		}
		*/
	}
}